package com.broad.commerce.code.services.jdbc;

import com.broad.commerce.code.base.AbstractXmlService;
import com.broad.commerce.code.modules.BaseModule;
import com.broad.commerce.code.modules.jdbc.EntityField;
import com.broad.commerce.code.modules.jdbc.MapperModule;
import com.broad.commerce.web.exception.ServiceException;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author stephen
 * @version V1.0
 * @date 2022-02-07 16:32
 * @description: MapperXmlModuleService
 **/
@Service
@SuppressWarnings("DuplicatedCode")
public class MapperModuleService extends AbstractXmlService {
	@Override
	public String createXmlCode(BaseModule baseModule) {
		if (!(baseModule instanceof MapperModule)) {
			throw new ServiceException("传入参数类型错误！应为 MapperModule");
		}
		return super.createXmlCode(baseModule);
	}

	/**
	 * Create class content.
	 * @param sb the sb
	 * @param baseModule the base module
	 */
	@Override
	protected void createXmlContent(StringBuilder sb, MapperModule mapperModule) {
		List<EntityField> entityFields = mapperModule.getEntityFields();
		//@off 查询所有数据
		sb.append("\n").append("\t").append("<select id=\"selectAll\" resultType=\"").append(mapperModule.getEntityFullClassName()).append("\">").append("\n")
		  .append("\t\t").append("SELECT U.* FROM ").append(mapperModule.getTableName().toUpperCase()).append(" AS U").append("\n")
		  .append("\t</select>").append("\n");//@on
	}
}
